<?php
$table = $this->uri->segment(3,0);
$url_ajax = base_url().'admin/ajax_field/order';
$url_ajax_sotrang = base_url().'admin/ajax_field/num';
$url_ajax_pub = base_url().'admin/ajax_field/pub/'.$table;
$url_ajax_where = base_url().'admin/ajax_field/where/'.$table;
?>
<script>
$(document).ready(function(){
    $('.show').click(function () {
        var dt= $(this).attr('class');
        var pub=0;  
        var id =  $(this).attr('name');      
        if(dt=='show'){
            pub =0;
             $(this).addClass("show unpublish");
        }else{
            pub=1;
            $(this).removeClass("unpublish");
        }
        //var data1 = 'publish=' + pub +'&id='+id;
         var url3 = '<?php echo $url_ajax_pub;?>';
        $.ajax({
          		type: "POST",
          		url: url3,
          		data: {publish: pub,id:id,data:1},
                success:function(data) {
                //$('.box_benh').html(data);
                //alert(data);                
                 },
                error: err                
        		});      
    });
    //*******************order ajax****************************************
    $(".box .ajax").click(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).attr('href');
        var url1 = '<?php echo $url_ajax;?>';
        $.ajax({
          		type: "POST",
          		url: url1,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    //********************* loc du lieu***********************************
    $(".action .locdulieu").change(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).val();
        var url2 = '<?php echo $url_ajax_where;?>';
        $.ajax({
          		type: "POST",
          		url: url2,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    //*********************chon so trang**********************************
    $(".sotrang #sotrang").change(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).val();
        var url2 = '<?php echo $url_ajax_sotrang;?>';
        $.ajax({
          		type: "POST",
          		url: url2,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    function callback(data, status){
        location.reload();
        //$("div .box_ajax").html(data);
      }
    
	function err(xhr, reason, ex){
	   alert('loi');
        $("div .box_ajax").html('loi');
      }
//*****************end order ajax******************/
});

</script>
    <!-- table -->
   
				<div class="box box_ajax">
					<!-- box / title -->
					<div class="title">
						<h5>Ghóp ý</h5>
                        <?php if($this->session->userdata('thongbao')){echo '<div class="thongbao">'.$this->session->userdata('thongbao').'</div>';$this->session->unset_userdata('thongbao');}?>
						<div class="search">
							<form action="#" method="post">
								<div class="input">
									<input type="text" id="search" name="search" />
								</div>
								<div class="button">
									<input type="submit" name="submit" value="Search" />
								</div>
							</form>
						</div>                        
					</div>
					<!-- end box / title -->
                    
                    <div class="edit_tool">
                            <a href="<?php echo base_url();?>admin/xuly/gopy/edit/" class="search">Thêm </a>
                    </div>
                   
                    <!-- edit tool-->
                    <?php if(!empty($data)){?>  
					<div class="table">
					
						<table>
							<thead>
								<tr>
									<th class="small_th"><a class="ajax" href="id">id</a><?php if($this->session->userdata('order')=='id'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
									<th style="width: 25%;"><a class="ajax" href="ten">Tên</a><?php if($this->session->userdata('order')=='ten'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
									<th style="width: 15%;"><a class="ajax" href="tieude">Tiêu đề</a><?php if($this->session->userdata('order')=='tieude'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
                                    <th style="width: 25%;"><a class="ajax" href="email">Email</a><?php if($this->session->userdata('order')=='email'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
									<th style="width: 15%;"><a class="ajax" href="dienthoai">Điện thoại</a><?php if($this->session->userdata('order')=='dienthoai'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
                                    <th class="small_th"><a class="ajax" href="created">Ngày tạo</a></th>                                    
                                    <th class="small_th"><a class="ajax" href="publish">Hiện</a></th>
                                    <th class="small_th">Sửa</th>
									<th class="small_th">Xóa</th>
                                    <th class="small_th"><input type="checkbox" class="checkall" /></th>
								</tr>
							</thead>
							<tbody>
                            <?php 
                            if(!empty($cat)){
                                foreach ($cat as $data2){
                                $mang[$data2->id]=$data2->title;
                            }
                            }
                           
                            $mang[0]="Danh mục gốc";                            
                            foreach ($data as $data){
                                echo '
                                <tr>
									<td>'.$data->id.'</td>
        	                        <td>'.$data->ten.'</td>
									<td>'.$data->tieude.'</td>
                                    <td>'.$data->email.'</td>
                                    <td>'.$data->dienthoai.'</td>
									<td>'.$data->created.'</td>';
                                    if($data->publish){
                                        echo '<td> <div class="show" name="'.$data->id.'" title="Hiện"></div></td>';
                                    }else echo '<td><div class="show unpublish" name="'.$data->id.'" title="Ẩn"></div></td>';								
                                    
                                    echo '
                                    <td><a href="'.base_url().'admin/xuly/gopy/edit/'.$data->id.'" class="edit"><img src="'.base_url().'template/admin/images/icons/edit.png" title="Sửa"></a></td>
                                    <td><a onclick="return confirm(\'Bạn có muốn xóa không?\');" href="'.base_url().'admin/xuly/gopy/xoa/'.$data->id.'"><img src="'.base_url().'template/admin/images/icons/xoa.png" title="xóa"></a></td>
									<td class="selected last"><input type="checkbox" /></td>
								</tr>                              
                                
                                ';                                
                            }?>	
                        						
							</tbody>
						</table>
                       
                         <?php }?>
						<!-- pagination -->
						<div class="pagination pagination-left">
							<div class="results">
								<span><?php if($result_mensenger){echo $result_mensenger;}?></span>
							</div>
                            
							<ul class="pager">
							<?php	echo $this->pagination->create_links();?>
							</ul>   
						</div>
						<!-- end pagination -->
                        <!-- chon so trang-->
                        <div class="sotrang">
                        Chọn số trường hiện thị:
                                <select name="sotrang" id="sotrang">                                
                                <?php
                                $t=0;
                                $limit = $this->session->userdata('limit');
                                for($i=0;$i<=11;$i++){
                                   $t=$t+10;
                                   echo  '<option value="'.$t.'" ';
                                   echo $t==$limit ? 'selected="selected"':'';                                   
                                   echo '>'.$t.'</option>';
                                }
                                ?>
								
							</select>
                            </div>
                         <!--end chon so trang-->
						<!-- table action -->
						<div class="action">
                        Lọc dữ liệu:
							<select name="cat" class="locdulieu">
                            <option <?php echo $dt=$this->session->userdata('goc'); if($dt==1){echo 'selected="selected"';}?> value="t0" class="locked">Chọn tất cả</option>
                            <option <?php $dt=$this->session->userdata('goc'); if($dt==2){echo 'selected="selected"';}?> value="goc" class="locked">Danh mục gốc</option>
                            <?php 
                            $value_where = $this->session->userdata('value_where');
                            if(!empty($cat)){
                                foreach($cat as $cat){
                                    echo '<option value="'.$cat->id.'" class="locked"';
                                    echo $value_where==$cat->id? 'selected="selected"':''; 
                                    echo '>'.$cat->title.'</option>';
                                }
                            }
                            ?>
							</select>
                            
						
                        
                            
						</div>
						<!-- end table action -->

					</div>
				</div>
				<!-- end table -->
                
                